import { useState } from 'react'
import { apiReqs, apiRequest } from '@/api'
import { Button, Input } from 'antd'
import { useNavigate } from 'react-router-dom'
import AddPeople from '@/pages/addPeople'
import imgLogo from './logo.jpg'
import './login.scss'

function Login() {
    // 创建路由钩子
    const navigate = useNavigate()

    // 组件中自维护的实时数据
    const [account, setAccount] = useState('')
    const [password, setPassword] = useState('')
    // 登录
    const login = () => {
        apiRequest({
            // url: "https://user-api-pre.airqualitychina.cn/auth/login",
            url: "http://0.0.0.0:8080/auth/login",
            data: {
                "account": account,
                "password": password === "123456" ? "lTsqJ09qyM0iS0pk0uW4hw==" : password,
                "system_code": "COMBINE",
                "mac_address": "g8qaDeG9tkdwqWoPXy63wg7TaUHMQYTXQyczk2q6pKlSM9ItQTo3NrwvUOPBCB",
                "sms_code": "",
                "aes_flag": true
            },
            success: (res) => {
                console.log(res)
                navigate('/addPeople')
            },
        })
    }
    return (
        <div className="P-login">
            <img src={imgLogo} alt="" className="logo" />
            <div className='p-number'>
                <div className="ipt-con">
                    <Input placeholder="账号" value={account} onChange={(e) => { setAccount(e.target.value) }} />
                </div>
                <div className="ipt-con">
                    <Input.Password placeholder="密码" value={password} onChange={(e) => { setPassword(e.target.value) }} />
                </div>
                <div className="ipt-con">
                    <Button type="primary" block={true} onClick={login}>登录</Button>
                </div>
            </div>
        </div>
    )
}

export default Login